package com.sgb.businessmodule.view.widget;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.sgb.businessmodule.R;
import com.sgb.businessmodule.entity.PickFilterEntity;
import com.swgk.core.customview.DecimalInputTextWatcher;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.util.MToast;

import java.util.List;

public class BudgetAmountPopWindow extends BasePopWindow {

    public BudgetAmountPopWindow(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_budget_amout;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        EditText editMinBudget = holder.getPop().findViewById(R.id.et_min_budget);
        EditText editMaxBudget = holder.getPop().findViewById(R.id.et_max_budget);
        TextView reset = holder.getPop().findViewById(R.id.reset);
        TextView confirm = holder.getPop().findViewById(R.id.confirm);

        //重置
        reset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editMinBudget.setText("");
                editMaxBudget.setText("");
            }
        });

        //确定
        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String minBudget = editMinBudget.getText().toString().trim();
                String maxBudget = editMaxBudget.getText().toString().trim();
                if (!TextUtils.isEmpty(minBudget) && !TextUtils.isEmpty(maxBudget)) {
                    if (Double.parseDouble(minBudget) > Double.parseDouble(maxBudget)) {
                        MToast.showToast(mContext, "最低预算不能高于最高预算");
                        return;
                    }
                }
                onResultClick.result(minBudget, maxBudget);
                dissMiss();
            }
        });

        //设置输出的数字的字数和小数点后几位限制
        editMinBudget.addTextChangedListener(new DecimalInputTextWatcher(editMinBudget, 10, 2, false));
        editMaxBudget.addTextChangedListener(new DecimalInputTextWatcher(editMaxBudget, 10, 2, false));
    }

    private OnResultClick onResultClick;

    public interface OnResultClick {

        void result(String minBudget, String maxBudget);
    }

    public void setOnResultClick(OnResultClick onResultClick) {
        this.onResultClick = onResultClick;
    }
}
